﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TinyCinema.UI.Pages.Schedule
{
    /// <summary>
    /// Interaction logic for ScheduleType.xaml
    /// </summary>
    public partial class SchedulePrice : Page
    {
        
        public StackPanel MainMenu { get; set; }
        public SchedulePrice()
        {
            InitializeComponent();
            MainMenu = FindResource("MainMenu") as StackPanel;
            (DataContext as Bussiness.Schedule.SchedulePrice).Messenger.Register<Bussiness.Schedule.Message.DeleteConfirmation>(this, ShowMessageBox1);
            (DataContext as Bussiness.Schedule.SchedulePrice).Messenger.Register<Bussiness.Schedule.Message.DeleteFailed>(this, ShowMessageBox2);
        }
        void ShowMessageBox1(Bussiness.Schedule.Message.DeleteConfirmation s)
        {
            s.Result = MessageBoxUtils.WPFMessageBox.Show((App.Current.FindResource("langMsgScheduleDelete") as String), "", MessageBoxButton.YesNo);
        }
        void ShowMessageBox2(Bussiness.Schedule.Message.DeleteFailed s)
        {
            MessageBoxUtils.WPFMessageBox.Show((App.Current.FindResource("langMsgScheduleNotDelete") as String), "", MessageBoxButton.OK);
        }
        private void MainMenuInitialized(object sender, EventArgs e)
        {
            (sender as StackPanel).DataContext = DataContext;
        }

        private void DataGrid_CurrentCellChanged(object sender, EventArgs e)
        {
            (DataContext as Bussiness.Schedule.SchedulePrice).SaveCommand.Execute(((sender as DataGrid).SelectedItem));
        }
        int PreCount;
        private void DataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            var Temp = sender as DataGrid;
            if (IsLoaded && Temp.Items.Count != PreCount)
            {
                Temp.ScrollIntoView(Temp.Items[Temp.Items.Count - 1], Temp.Columns[2]);
                Temp.SelectedIndex = Temp.Items.Count - 1;
                Temp.Focus();
            }
            PreCount = Temp.Items.Count;
            Temp.Focus();
        }

    }
}
